import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getParameter")
public class GetParameter extends HttpServlet {

    ObjectMapper objectMapper = new ObjectMapper();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 解析 JSON数据  ---->  ObjectMapper对象
        User user = objectMapper.readValue(req.getInputStream(), User.class);
        resp.getWriter().write(user.toString());
    }
}
class User{
    public int userId;
    public int classId;
    @Override
    public String toString() {
        return "User{" +
                "userId=" + userId +
                ", classId=" + classId +
                '}';
    }
}